﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NRemedy;
using NRemedy.Linq;
using Oracle.DataAccess.Client;
using BMC.ARSystem;


namespace ITSM.Emergency
{
    class Program
    {
        static void Main(string[] args)
        {

            /*
            using (ARLoginContext context = new ARLoginContext("10.188.238.23", "Demo", "asb#1234"))
            {
                //ARProxy<CTMPeople> proxy = new ARProxy<CTMPeople>(context);
                BMC.ARSystem.Server server = new BMC.ARSystem.Server();
                server.Login("10.188.238.23", "Demo", "asb#1234");

                using (OracleDataAccess oda = new OracleDataAccess())
                {

                    OracleDataReader dr = oda.ExecuteReader("select person_id,first_name,last_name from ctm_people");
                    int count = 1;
                    while (dr.Read())
                    {
                        
                        if (dr["person_id"] == null)
                            continue;
                        string firstname = dr["first_name"] == null ? null : dr["first_name"].ToString();
                        string lastname = dr["last_name"] == null ? null : dr["last_name"].ToString();

                        
                        //CTMPeople people = new CTMPeople();
                        //people.Request_ID = dr["person_id"].ToString();
                        //people.FirstName = firstname;
                        //people.LastName = lastname;
                        //people.ChangedProperties["FirstName"] = true;
                        //people.ChangedProperties["LastName"] = true;
                        //proxy.SetEntry(people);

                        FieldValueList fvl = new FieldValueList();
                        fvl.Add(1000000019u, lastname);
                        fvl.Add(1000000018u, firstname);
                        server.SetEntry("CTM:People", dr["person_id"].ToString(), fvl);
                        Console.WriteLine(count.ToString() + firstname + lastname);
                        count++;
                    }
                }

                server.Logout();


            }
             * 
             * */

            BMC.ARSystem.Server server = new BMC.ARSystem.Server();
            try
            {
                server.Login("10.188.238.23", "Demo", "asb#1234");
                int count = 1;
                using (OracleDataAccess oda = new OracleDataAccess())
                {
                    OracleDataReader dr = oda.ExecuteReader("select request_id from ar_system_user_preference");

                    while (dr.Read())
                    {
                        if (dr["request_id"] == null) continue;
                        FieldValueList fvl = new FieldValueList();
                        fvl.Add(20123u, "Asia/Hong_Kong");
                        server.SetEntry("AR System User Preference", dr["request_id"].ToString(), fvl);
                        Console.WriteLine(count.ToString() + ":" + dr["request_id"].ToString());
                        count++;
                    }
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);

            }
            finally
            {
                server.Logout();
            }


        }
    }
}
